<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div style="display: flex; align-items: center; justify-content: center; height: 100vh;">
        <canvas id="canvas" width="500" height="1000"></canvas>
    </div>

    <script>
        const canvas = document.querySelector('#canvas')

        const ctx = canvas.getContext('2d')

        ctx.beginPath()

        ctx.moveTo(100,100)
        ctx.lineTo(200,100)
        ctx.lineTo(100,200)
        ctx.lineTo(100,100)

        ctx.lineWidth = 8
        ctx.strokeStyle = "red"

        // 闭合连续线段
        ctx.closePath();
    
        
        ctx.stroke()
    </script>
    
</body>
</html>